package myjava.i_collection;

import java.util.*;

/**
 * @Auther: cty
 * @Date: 2020/7/16 21:31
 * @Description:
 * @version: 1.0
 */
public class TestHash {

    public static void main(String[] args) {
        // hashCode()
        Object object = new Object();
        System.out.println(object.hashCode());  // 460141958 调用本地方法

        System.out.println(new String("12").hashCode());  // 1569=50+31*(49+31*0)

        System.out.println(new Character('a').hashCode());  // 97 ASCII码

        System.out.println(new Byte((byte) 8).hashCode());  // 8  自身
        System.out.println(new Short((short) 16).hashCode());  // 16  自身
        System.out.println(new Integer(32).hashCode());  // 32  自身
        System.out.println(new Long(64).hashCode());  // 64  自身

        System.out.println(new Float(2.0).hashCode());  // 1073741824  调用本地方法
        System.out.println(new Double(2.0).hashCode());  // 1073741824  调用本地方法
        System.out.println("----------------------------------------------------------");

        // hash
        String str = "test";
        HashMap<Object,String> map = new HashMap<>();
        map.put(new Integer(32),str);  // h^(h>>>16) 扰动函数-减少hash碰撞、h&(n-1)位运算实现取模-提高运算效率
        // [HashMap的底层实现](https://www.cnblogs.com/handongxue/p/12819953.html)
        System.out.println("----------------------------------------------------------");

    }  // end main
}  // end class

/**
 * 460141958
 * 1569
 * 97
 * 8
 * 16
 * 32
 * 64
 * 1073741824
 * 1073741824
 * ----------------------------------------------------------
 * ----------------------------------------------------------
 */
